package org.flashIso.engine.core {

	/**
	 * @author Marius Dorin Moraru
	 */
	public class RotationMatrix {

		private static var piOver180:Number = Math.PI / 180;
		
		public static function getRotationMatrix(point : Point3D, alpha : Number) : Array {
			var cos : Number = Math.cos(alpha);
			var sin : Number = Math.sin(alpha);
			
			return new Array
			([point.x * point.x + (1 - point.x * point.x) * cos, 	point.x * point.y * (1 - cos) + point.z * sin,		point.x * point.z * (1 - cos) - point.y * sin],
				[point.x * point.y * (1 - cos) - point.z * sin, 	point.y * point.y + (1 - point.y * point.y) * cos,		point.y * point.z * (1 - cos) + point.x * sin],
				[point.x * point.z * (1 - cos) + point.y * sin, 	point.y * point.z * (1 - cos) - point.x * sin,		point.z * point.z + (1 - point.z * point.z) * cos]);
		}
		public static function getRotationMatrixAroundZero(alpha : Number) : Array {
			
			var cos : Number = Math.cos(alpha);
			var sin : Number = Math.sin(alpha);
			
			return new Array
			([cos, 	sin, 0],
			[-sin, cos, 0],
			[0, 0, 1]);
		}
		
		public static function rotatePoint(p:Point3D, alpha:Number) : Point3D{
			alpha = alpha * piOver180; 
			var cos : Number = Math.cos(alpha);
			var sin : Number = Math.sin(alpha);

			var newP:Point3D = new Point3D;
			newP.x = p.x * cos - p.y * sin; 
			newP.y = p.x * sin + p.y * cos; 
			newP.z = p.z;
			return newP;
		}
		
	}
}
